﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace TaxonomyReader
{
    public enum XsdPeriodType
    {
        instant, duration
    }

    public enum XsdBalance
    {
        credit, debit
    }

    public enum XsdType
    {
        [DescriptionAttribute("Monetary")]
        monetaryItemType,
        [DescriptionAttribute("Decimal")]
        sharesItemType,
        [DescriptionAttribute("Decimal")]
        pureItemType, 
        [DescriptionAttribute("nonZeroDecimal")]
        nonZeroDecimalItemType,
        [DescriptionAttribute("Decimal")]
        decimalItemType,
        [DescriptionAttribute("String")]
        stringItemType,
        [DescriptionAttribute("??")]
        dateItemType
    }

    public enum XsdSubstitutionGroup
    {
        item, dimensionItem, tupleItem, hypercubeItem
    }

    public enum XLinkType
    {
        simple
    }

    public enum LinkBaseType
    {
        [DescriptionAttribute("http://www.xbrl.org/2003/role/presentationLinkbaseRef")]
        presentationLink,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/definitionLinkbaseRef")]
        definitionLink,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/calculationLinkbaseRef")]
        calculationLink,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/labelLinkbaseRef")]
        labelLink,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/referenceLinkbaseRef")]
        referenceLink
    }

    public enum ArcRole
    {
        [DescriptionAttribute("http://www.w3.org/1999/xlink/properties/linkbase")]
        Linkbase,
        [DescriptionAttribute("http://www.xbrl.org/2003/arcrole/parent-child")]
        Parent_Child,
        [DescriptionAttribute("http://www.xbrl.org/2003/arcrole/summation-item")]
        Summation_Item,
        [DescriptionAttribute("http://www.xbrl.org/2003/arcrole/concept-label")]
        Concept_Label,
        [DescriptionAttribute("http://xbrl.org/int/dim/arcrole/all")]
        Element_HyperCube_All,
        [DescriptionAttribute("http://xbrl.org/int/dim/arcrole/notAll")]
        Element_HyperCube_NotAll,
        [DescriptionAttribute("http://xbrl.org/int/dim/arcrole/hypercube-dimension")]
        Hypercube_Dimension,
        [DescriptionAttribute("http://xbrl.org/int/dim/arcrole/dimension-domain")]
        Dimension_Domain,
        [DescriptionAttribute("http://xbrl.org/int/dim/arcrole/domain-member")]
        Domain_Member,
        [DescriptionAttribute("http://xbrl.org/int/dim/arcrole/dimension-default")]
        Dimension_Default
    }

    public enum ContextElement
    {
        segment,scenario
    }

    public enum LabelRole
    {
        [DescriptionAttribute("http://www.xbrl.org/2003/role/label")]
        label,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/terseLabel")]
        terseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/verboseLabel")]
        verboseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/positiveLabel")]
        positiveLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/positiveTerseLabel")]
        positiveTerseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/positiveVerboseLabel")]
        positiveVerboseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/negativeLabel")]
        negativeLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/negativeTerseLabel")]
        negativeTerseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/negativeVerboseLabel")]
        negativeVerboseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/zeroLabel")]
        zeroLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/zeroTerseLabel")]
        zeroTerseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/zeroVerboseLabel")]
        zeroVerboseLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/totalLabel")]
        totalLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/periodStartLabel")]
        periodStartLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/periodEndLabel")]
        periodEndLabel,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/documentation")]
        documentation,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/definitionGuidance")]
        definitionGuidance,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/disclosureGuidance")]
        disclosureGuidance,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/presentationGuidance")]
        presentationGuidance,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/measurementGuidance")]
        measurementGuidance,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/commentaryGuidance")]
        commentaryGuidance,
        [DescriptionAttribute("http://www.xbrl.org/2003/role/exampleGuidance")]
        exampleGuidance,
        [DescriptionAttribute("http://xbrl.iasb.org/role/label/alternativeLabel")]
        alternativeLabel,
        [DescriptionAttribute("http://xbrl.iasb.org/role/label/labelNegated")]
        labelNegated,
        [DescriptionAttribute("http://xbrl.iasb.org/role/label/terseLabelNegated")]
        terseLabelNegated,
        [DescriptionAttribute("http://xbrl.iasb.org/role/label/totalLabelNegated")]
        totalLabelNegated,
        [DescriptionAttribute("http://xbrl.iasb.org/role/label/netLabel")]
        netLabel,
        [DescriptionAttribute("http://xbrl.us/us-gaap/role/label/negated")]
        negated,
        [DescriptionAttribute("http://xbrl.us/us-gaap/role/label/negatedTotal")]
        negatedTotal,
        [DescriptionAttribute("http://xbrl.us/us-gaap/role/label/negatedPeriodStart")]
        negatedPeriodStart,
        [DescriptionAttribute("http://xbrl.us/us-gaap/role/label/negatedPeriodEnd")]
        negatedPeriodEnd
    }

    public enum ArcUse
    {
        prohibit, use
    }

 
    public static class EnumExtensions
    {
        public static object GetEnumValue(string role, Type T)
        {
            foreach (string s in Enum.GetNames(T))
            {
                Enum e = (Enum)Enum.Parse(T, s);

                if (e.ToDescriptionString() == role)
                    return e;
            }

            return ArcRole.Linkbase;
        }

        public static string ToDescriptionString(this Enum val)
        {
            DescriptionAttribute[] attributes = (DescriptionAttribute[])val.GetType()
                .GetField(val.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);

            return attributes.Length > 0 ? attributes[0].Description : string.Empty;
        }
    }
}
